{% extends "GitonomyWebsiteBundle::layout_project.html.twig" %}

{% trans_default_domain "project_permissions" %}

{% block title 'page.title'|trans({'%project%': project.name}) %}

{% set global_navigation = 'projects' %}
{% set local_navigation = 'permissions' %}

{% block project_content %}
    <div id="content">
        <form method="POST" action="{{ path('project_postPermissionsCreateRole', {slug: project.slug}) }}" id="user-role">
            {{ form_errors(roleForm) }}
            <table class="bordered-table table table-striped">
                <legend>{{ 'title.user_role'|trans }}</legend>
                <thead>
                    <tr>
                        <th>{{ 'table.role.column.user'|trans }}</th>
                        <th>{{ 'table.role.column.role'|trans }}</th>
                        <th>{{ 'table.role.column.actions'|trans }}</th>
                    </tr>
                </thead>
                <tbody>
                    {% for userRole in project.userRoles %}
                        {% set user = userRole.user %}
                        {% set role = userRole.role %}
                        <tr>
                            <td>{{ user.fullname }}</td>
                            <td>{{ role.name }}</td>
                            <td>
                                <div class="btn-group pull-right">
                                    <a rel="tooltip" title="{{ 'tooltip.role.delete'|trans }}" class="btn btn-small btn-danger" data-method="POST" data-confirm="{{ 'button.role.confirm.delete'|trans({'%user%': user.fullname, '%role%': role.name}) }}" href="{{ path('project_postPermissionsDeleteRole', {slug: project.slug, id: userRole.id, _token: csrf_token('project_permissions') }) }}"><i class="icon-fire icon-white"></i></a>
                                </div>
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
                <tfoot>
                    <tr>
                        <td>
                            {{ form_widget(roleForm.user) }}
                            {{ form_errors(roleForm.user) }}
                        </td>
                        <td>
                            {{ form_widget(roleForm.role) }}
                            {{ form_errors(roleForm.role) }}
                        </td>
                        <td>
                            <div class="btn-group pull-right">
                                <input type="submit" class="btn btn-success" value="{{ 'form.role.submit'|trans }}" />
                            </div>
                        </td>
                    </tr>
                </tfoot>
            </table>
            {{ form_rest(roleForm) }}
        </form>
        <form method="POST" action="{{ path('project_postPermissionsCreateGitAccess', {slug: project.slug}) }}" id="git-access">
            <legend>{{ 'title.git_accesses'|trans }}</legend>
            {{ form_errors(gitAccessForm) }}
            <table class="bordered-table table table-striped git-accesses">
                <thead>
                    <tr>
                        <th>{{ 'table.git_accesses.column.role'|trans }}</th>
                        <th>{{ 'table.git_accesses.column.reference'|trans }}</th>
                        <th>{{ 'table.git_accesses.column.write'|trans }}</th>
                        <th>{{ 'table.git_accesses.column.admin'|trans }}</th>
                        <th>{{ 'table.git_accesses.column.actions'|trans }}</th>
                    </tr>
                </thead>
                <tbody>
                    {% for gitAccess in project.gitAccesses %}
                        <tr>
                            <td>{{ gitAccess.role.name }}</td>
                            <td>{{ gitAccess.reference }}</td>
                            <td>{{ (gitAccess.write ? '<i class="symbol">ok</i>' : '&nbsp;')|raw }}</td>
                            <td>{{ (gitAccess.admin ? '<i class="symbol">ok</i>' : '&nbsp;')|raw }}</td>
                            <td>
                                <div class="btn-group pull-right"><a rel="tooltip" data-placement="left" title="{{ 'tooltip.git_access.delete'|trans({'%role%': gitAccess.role.name, '%reference%': gitAccess.reference}) }}" class="btn btn-small btn-danger" data-method="POST" data-confirm="{{ 'button.git_access.confirm.delete'|trans({'%role%': gitAccess.role.name, '%reference%': gitAccess.reference}) }}" href="{{ path('project_postPermissionsDeleteGitAccess', {slug: project.slug, id: gitAccess.id, _token: token}) }}"><i class="icon-fire icon-white"></i></a></div>
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
                <tfoot>
                    <tr>
                        <td>
                            {{ form_widget(gitAccessForm.role) }}
                            {{ form_errors(gitAccessForm.role) }}
                        </td>
                        <td>
                            {{ form_widget(gitAccessForm.reference) }}
                            {{ form_errors(gitAccessForm.reference) }}
                        </td>
                        <td>
                            {{ form_widget(gitAccessForm.write) }}
                            {{ form_errors(gitAccessForm.write) }}
                        </td>
                        <td>
                            {{ form_widget(gitAccessForm.admin) }}
                            {{ form_errors(gitAccessForm.admin) }}
                        </td>
                        <td><div class="btn-group pull-right"><input type="submit" class="btn btn-success" value="{{ 'form.git_access.submit'|trans }}" /></div></td>
                    </tr>
                </foot>
            </table>
            {{ form_rest(gitAccessForm) }}
        </form>
    </div>
{% endblock %}
